<template>
	<view>
		<!-- <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				
				<view class="swiper-item">
					<image :src="item.image_src" mode=""></image>
				</view>
			</swiper-item>
		
		</swiper> -->
		<view class="search-box">
			<my-search ></my-search>
		</view>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,i) in swiperList" :key="i">
				<navigator :url="'../../subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id" class="swiper-item">
					<image :src="item.image_src" mode=""></image>
				</navigator>
			</swiper-item>
		</swiper>
		
		<view class="nav-list">
			<view @click="navClickHandler(item)" class="nav-item" v-for="(item,i) in navList" :key='i'>
				<image :src="item.image_src"></image>
			</view>
		</view>
		<view class="floor-list" v-for="(item,index) in floorList" :key="index">
			<view class="floor_item">
				<image class="floor-title" :src="item.floor_title.image_src" mode=""></image>
			</view>
			
			<view class="floor-img-box">
				<navigator class="left-img-box" :url="item.product_list[0].url">
					<image :src="item.product_list[0].image_src" mode="" :style="{ width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
				</navigator>
				
				<view class="right-img-box">
					<navigator class="right-img-item" v-for="(item2,index) in item.product_list" :key='index' v-if="index !==0 " :url="item2.url" >
						<image :src="item2.image_src" mode="" :style="{width: item2.image_width + 'rpx'}" mode="widthFix"></image>
					</navigator>
				</view>
			</view>
		
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList:[],
				navList:[],
				floorList:[]
			};
		},
		onLoad(){
			this.getSwiperList(),
			this.getNavList(),
			this.getFloorList()
		},
		methods:{
			async getFloorList(){
				const {data :res} = await uni.$http.get('/api/public/v1/home/floordata')
				if (res.meta.status != 200) return uni.$showMsg();
				res.message.forEach(floor=>{
					floor.product_list.forEach(product=>{
				 
						product.url = '/subpkg/goods_list/goods_list?'+product.navigator_url.split('?')[1];
						console.log(product.url)
					})
				})
				console.log(res.message)
				
				this.floorList = res.message;
			},
			
			async getNavList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/catitems')
				if(res.meta.status != 200)
				return uni.$showMsg();
				
				this.navList = res.message;
			},
			async getSwiperList(){
				const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
				if(res.meta.status != 200)
				return uni.$showMsg();
			
				this.swiperList = res.message;
			},
			navClickHandler(item){
					
				if (item.name === '分类') {
					uni.switchTab({
						url:'../cate/cate'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	
	.search-box {
		position: sticky;
		top: 0;
		z-index: 100;
	}
	swiper {
		height: 330rpx;
		.swiper-item,image{
			width: 100%;
			height: 100%;
		}
	}
	.nav-list {
		display: flex;
		width: 100%;
		// background-color: red;
		flex-direction: row;
		flex-wrap:nowrap;
		justify-content:space-around;
		margin:15rpx 0rpx;
	}
	.nav-item image {
		width: 128rpx;
		height: 140rpx;
	}
	
	.floor-img-box {
		display: flex;
		padding-left: 10rpx;
	}
	
	.right-img-box {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}
	
	.floor_item {
		height: 60rpx;
		width: 100%;
	
	} 
	.floor-title{
		width: 100%;
		height: 60rpx;
	}
</style>
